package com.example.a14110100420.yuejian.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import com.example.a14110100420.yuejian.R;


public class RegisterActivity extends AppCompatActivity {
    private EditText username,pwd,pwd2,tel,email;
    private Button reg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initViews();
        initEvents();
    }
    public void initEvents(){
     /*   reg.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                String user = username.getText().toString();
                String password = pwd.getText().toString();
                String password2 = pwd2.getText().toString();
                String tele = tel.getText().toString();
                String aemail = email.getText().toString();
                if(user.equals("") || password.equals("") || password2.equals("")|| tele.equals("")|| aemail.equals("")){
                    Toast.makeText(RegisterActivity.this, "您有的信息还未填写", Toast.LENGTH_SHORT).show();
                }else{
                    if(password.equals(password2)){
                        UserModel userModel = new UserModel();
                        Call<PersonalService> call = userModel.register(user,password,password2,tele,aemail);
                        //3. 发送请求
                        call.enqueue(new Callback<PersonalService>(){
                            @Override
                            public void onFailure(Call<PersonalService> uname, Throwable throwable) {
                                Toast.makeText(RegisterActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
                            }
                            @Override
                            public void onResponse(Call<PersonalService> uname, Response<PersonalService> response) {
                                String result = response.body().getSuccess().trim();
                                if(result.equals("0")){
                                    Toast.makeText(RegisterActivity.this, "该用户名已被注册", Toast.LENGTH_SHORT).show();
                                } else{
                                    Toast.makeText(RegisterActivity.this, result+"注册成功", Toast.LENGTH_SHORT).show();
                                    Intent intent = new Intent();
                                    String user=username.getText().toString();
                                    intent.putExtra("username",user);
                                    setResult(RESULT_OK,intent);
                                    finish();
                                }
                            }
                        });
                    }
                    else{
                        Toast.makeText(RegisterActivity.this, "两次密码输入不同请确认", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });*/
    }
    public void initViews(){
        username = (EditText)findViewById(R.id.username);
        pwd = (EditText)findViewById(R.id.pwd);
        pwd2 = (EditText)findViewById(R.id.pwd2);
        tel = (EditText)findViewById(R.id.tel);
        email = (EditText)findViewById(R.id.email);


    }

}
